# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=k0sctl
pkgver=0.18.1
pkgrel=0
pkgdesc="Bootstrapping and management tool for k0s clusters"
url="https://github.com/k0sproject/k0sctl"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/k0sproject/k0sctl/archive/refs/tags/v$pkgver/k0sctl-$pkgver.tar.gz"
options="chmod-clean"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make TAG_NAME="v$pkgver" GIT_COMMIT=""

	for shell in bash fish zsh; do
		./$pkgname completion --shell $shell >$pkgname.$shell
	done
}

check() {
	make test
}

package() {
	make PREFIX=/usr DESTDIR="$pkgdir" install

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
4e9f461dd0ff6580f04959400fd90344b1af4158d26139295a08f6ee686965868ad58798e30303b8ad6550f245c7c953a9400f834c9d56d5e30ec8ad16dae4a5  k0sctl-0.18.1.tar.gz
"
